package operation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class Del implements IOoperation{
    public void work(Booklist book) {
        System.out.println("删除图书！");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要删除书的书名");
        String bookName = sc.nextLine();
        int cnt= book.getCount();
        int index=-1;
        for (int i = 0; i < cnt; i++) {
            Book book1 = book.getBooks(i);
            if(book1.getName().equals(bookName)){
                index = i;
            }
        }
        if(index==-1){
            System.out.println("不存在该书！");
        }
        for (int i = index; i < cnt-1; i++) {
            Book book2=book.getBooks(i+1);
            book.addBook(book2,i);
        }
        book.getSize(cnt-1);
        System.out.println("删除成功！");
    }
}
